package com.shangyueshang.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shangyueshang.model.SysMenu;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author JokeyFeng
 * @date: 2022/1/3
 * @project: shangyueshang
 * @package: com.shangyueshang.mapper
 * @comment:
 */
@Component
public interface SysMenuMapper extends BaseMapper<SysMenu> {

    /**
     * 根据用户名查询菜单
     *
     * @param username
     * @return
     */
    @Select("select " +
            "   m.* " +
            "from " +
            "   sys_menu m, " +
            "   sys_user u, " +
            "   sys_user_role ur, " +
            "   sys_role_menu rm " +
            "where " +
            "   u.name = #{username} " +
            "   and u.id = ur.user_id " +
            "   and ur.role_id = rm.role_id" +
            "   and m.id = rm.menu_id" +
            "   and m.del_flag = 0 ")
    List<SysMenu> findByUsername(@Param("username") String username);

    /**
     * 查询角色菜单
     *
     * @param roleId
     * @return
     */
    @Select("select " +
            "   m.* " +
            "from " +
            "   sys_menu m, " +
            "   sys_role_menu rm " +
            "where " +
            "   rm.role_id = #{roleId} " +
            "   and m.id = rm.menu_id ")
    List<SysMenu> findByRole(@Param(value = "roleId") Long roleId);
}
